<style type="text/css" title="currentStyle">
	@import "../media/css/demo_page.css";
	@import "../media/css/demo_table_jui.css";
	@import "../examples_support/themes/smoothness/jquery-ui-1.8.4.custom.css";
	@import "media/css/TableTools_JUI.css";
</style>
<script type="text/javascript" charset="utf-8" src="../media/js/jquery.dataTables.js"></script>
<script type="text/javascript" charset="utf-8" src="media/js/ZeroClipboard.js"></script>
<script type="text/javascript" charset="utf-8" src="media/js/TableTools.js"></script>
<script type="text/javascript" charset="utf-8">
	$(document).ready( function () {
		$('#example').dataTable( {
			"bJQueryUI": true,
			"sPaginationType": "full_numbers",
			"sDom": 'Tlfrtip',	
			"oTableTools": {
				"aButtons": [
					"copy", "csv", "xls", "pdf", "print",
					{
						"sExtends":    "collection",
						"sButtonText": "Save",
						"aButtons":    [ "csv", "xls", "pdf" ]
					}
				]
			}
		} );
	} );
</script>
<?php
 $sql = "SELECT * FROM tb_client_subscription,tb_clientinfo WHERE ci_id = tcs_clientId  AND tcs_clientId = ".$_POST[txtClientId]." AND tcs_deviceId = ".$_POST[txtDeviceId]." ORDER BY ci_clientName DESC";
	$rows = $db->query($sql);
    $totRec = $db->affected_rows;
?>
<script language="javascript">
function funEditUser(uid,cid,did)
{
	document.frmSubmit.txtSubsId.value = uid;
	document.frmSubmit.txtClientId.value = cid;
	document.frmSubmit.txtDeviceId.value = did;
	document.frmSubmit.action = '?ch=addSubscription';
	document.frmSubmit.submit();
}
</script>
<?php if($totRec == 0) { ?>
<div align="left" class="listofusers">&nbsp;<a href="#" onclick="funEditUser('','<?php echo $_POST[txtClientId];?>','<?php echo $_POST[txtDeviceId];?>')">Add New Subs.</a></div>
<?php } ?>
<table cellpadding="0" cellspacing="0" border="0" class="gridform_final" id="example">
<thead>
    <tr>
        <th width="20%">Client Name</th>
        <th width="10%">Device Id   </th>
        <th width="10%">Renewal Date</th> 
        <th width="10%">Expiry Date</th>
        <th width="10%">Remaining Days</th>
        <th width="10%">Amount & Type</th>
        <th width="10%">Edit</th>
   </tr>
       </thead>
 <tbody>
   <?php
  
   if($totRec  > 0)
   {
   $i = 1;
   	while ($record = $db->fetch_array($rows)) 
	{
		
//		echo strtotime("-1 days ".($record[tcs_noOfMonths]) ."months ".$record[tcs_renewalDateFrom]);
		$renewDate = strtotime($record[tcs_renewalDateTo]);
		$toDate = strtotime(date("d-m-Y"))	;
		//echo $renewDate." >= ".$toDate;
		if($renewDate >= $toDate )
		{
			$addFlag = 1;
			$remain = dateDiff(date("d-m-Y"),date("d-m-Y",strtotime($record[tcs_renewalDateTo])));
		}
		else 
		{
			$addFlag = 0;
			$remain = "Expired";
		}
		
		//echo $record[tcs_isActive]." ".$addFlag;
		//echo "<br>";
		//echo date("d-m-Y",strtotime("-1 days ".($record[tcs_noOfMonths]) ."months ".$record[tcs_renewalDateFrom]));
		if($record[tcs_payType] == "Cheque")
			$payType = $record[tcs_amount]." (".$record[tcs_payType]." - ".$record[tcs_chequeNo].")";
		else
			$payType = $record[tcs_amount]." (".$record[tcs_payType].")";
	?>
		<tr>
        <td><?php echo ucfirst($record[ci_clientName]);?></td>
        <td><?php echo ucfirst($util->getDeviceInfoByDeviceId($record[tcs_deviceId]));?></td>
        <td><?php echo date("d-m-Y",strtotime($record[tcs_renewalDateFrom]));?> </td> 
        <td><?php echo date("d-m-Y",strtotime($record[tcs_renewalDateTo]));?> </td>
        <td><?php echo $remain; ?> </td>
        <td><?php echo $payType;?> </td>
        <td><?php if($addFlag == 1 && $record[tcs_isActive] == 1) { ?><img src="../../images/edit.gif" style="cursor:pointer;" width="45" height="16" border="0" onclick="funEditUser('<?php echo $record[tcs_id];?>','<?php echo $record[tcs_clientId];?>','<?php echo $record[tcs_deviceId];?>')" /><?php } else if($totRec == $i){ ?>
		<a href="#" onclick="funEditUser('','<?php echo $record[tcs_clientId];?>','<?php echo $record[tcs_deviceId];?>')">Renew</a>
		<?php } else echo '---'; ?></td>
   </tr>
    <?php
	$i++;
	}
	}
   ?>
  </tbody>
</table>
<form name="frmSubmit" id="frmSubmit" method="post">
	<input type="hidden" name="txtSubsId" id="txtSubsId" />
   	<input type="hidden" name="txtClientId" id="txtClientId" />
    <input type="hidden" name="txtDeviceId" id="txtDeviceId" />
</form>